package com.hlt.shuiliting.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hlt.shuiliting.dao.GongChengXMDAO;
import com.hlt.shuiliting.dao.ZhengDiCQDAO;
import com.hlt.shuiliting.valuebean.ZhengDiCQ;

public class ZhengDiCQServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public ZhengDiCQServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("UTF-8");//�������Ĳ���
		response.setCharacterEncoding("UTF-8");//�������Ĳ���

		String servletPath = request.getServletPath();
		if (servletPath.equalsIgnoreCase("/listZhengDiCQ")) {
			listZhengDiCQ(request, response);
		} else if (servletPath.equalsIgnoreCase("/viewZhengDiCQ")) {
			viewZhengDiCQ(request, response);
		} else if (servletPath.equalsIgnoreCase("/insertZhengDiCQ")) {
			insertZhengDiCQ(request, response);
		} else if (servletPath.equalsIgnoreCase("/updateZhengDiCQ")) {
			updateZhengDiCQ(request, response);
		} else if (servletPath.equalsIgnoreCase("/deleteZhengDiCQ")) {
			deleteZhengDiCQ(request, response);
		}
	}

	public void listZhengDiCQ(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ZhengDiCQDAO zhengDiCQDAO = new ZhengDiCQDAO();
		GongChengXMDAO gongChengXMDAO = new GongChengXMDAO();
		String pageSize = request.getParameter("pageSize");
		String pageNum = request.getParameter("pageNum");
		String GongChengXMID = request.getParameter("GongChengXMID");
		
		List list = zhengDiCQDAO.list(Integer.parseInt(GongChengXMID), (Integer.parseInt(pageSize)), (Integer.parseInt(pageNum)));
		Map map = (Map)gongChengXMDAO.view(Integer.parseInt(GongChengXMID));
		String pageCount = Integer.toString(zhengDiCQDAO.getPageCount());
		
		request.setAttribute("pageCount", pageCount);
		request.setAttribute("pageNum", pageNum);
		request.setAttribute("gongChengXM", map);
		request.setAttribute("zhengDiCQLIST", list);
		
		request.getRequestDispatcher("/ZhengDiCQ_List.jsp").forward(request, response);
	}
	
	public void viewZhengDiCQ(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ZhengDiCQDAO zhengDiCQDAO = new ZhengDiCQDAO();
		String ID = request.getParameter("ID");
		String viewOrUpdate = request.getParameter("viewOrUpdate");
		Map map = zhengDiCQDAO.view(Integer.parseInt(ID));
		request.setAttribute("zhengDiCQ", map);
		
		if (viewOrUpdate.equalsIgnoreCase("view")) {
			request.getRequestDispatcher("ZhengDiCQ_View.jsp").forward(request, response);
		} else if (viewOrUpdate.equalsIgnoreCase("update")) {
			request.getRequestDispatcher("ZhengDiCQ_Update.jsp").forward(request, response);
		}
	}
	
	public void insertZhengDiCQ(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ZhengDiCQDAO zhengDiCQDAO = new ZhengDiCQDAO();
		ZhengDiCQ zhengDiCQ = new ZhengDiCQ();
		
		String ZhuangTai = request.getParameter("ZhuangTai");
		String JiLuSJ = request.getParameter("JiLuSJ");
		String LuRuR = request.getParameter("LuRuR");
		String XiangMuYDSPBM = request.getParameter("XiangMuYDSPBM");
		String XiangMuYDSPYJ = request.getParameter("XiangMuYDSPYJ");
		String XiangMuYDXKZMH = request.getParameter("XiangMuYDXKZMH");
		String ChaiQianFZDW = request.getParameter("ChaiQianFZDW");
		String ChaiQianFZR = request.getParameter("ChaiQianFZR");
		String XiangMuZDCQGGBM = request.getParameter("XiangMuZDCQGGBM");
		String ChaiQianFW = request.getParameter("ChaiQianFW");
		String ChaiQianSJ = request.getParameter("ChaiQianSJ");
		String ChaiQianFS = request.getParameter("ChaiQianFS");
		String ShangQiYZFJE = request.getParameter("ShangQiYZFJE");
		String BenQiZFJE = request.getParameter("BenQiZFJE");
		String LeiJiZFJE = request.getParameter("LeiJiZFJE");
		String GongChengXMID = request.getParameter("GongChengXMID");
		
		zhengDiCQ.setZhuangTai(ZhuangTai);	
		zhengDiCQ.setJiLuSJ(JiLuSJ);	
		zhengDiCQ.setLuRuR(LuRuR);	
		zhengDiCQ.setXiangMuYDSPBM(XiangMuYDSPBM);	
		zhengDiCQ.setXiangMuYDSPYJ(XiangMuYDSPYJ);	
		zhengDiCQ.setXiangMuYDXKZMH(XiangMuYDXKZMH);	
		zhengDiCQ.setChaiQianFZDW(ChaiQianFZDW);	
		zhengDiCQ.setChaiQianFZR(ChaiQianFZR);	
		zhengDiCQ.setXiangMuZDCQGGBM(XiangMuZDCQGGBM);	
		zhengDiCQ.setChaiQianFW(ChaiQianFW);	
		zhengDiCQ.setChaiQianSJ(ChaiQianSJ);	
		zhengDiCQ.setChaiQianFS(ChaiQianFS);	
		zhengDiCQ.setShangQiYZFJE(ShangQiYZFJE);	
		zhengDiCQ.setBenQiZFJE(BenQiZFJE);	
		zhengDiCQ.setLeiJiZFJE(LeiJiZFJE);	
		zhengDiCQ.setGongChengXMID(GongChengXMID);

		zhengDiCQDAO.insert(zhengDiCQ);
		
		response.sendRedirect("listZhengDiCQ?GongChengXMID=" + GongChengXMID);
	}
	
	public void updateZhengDiCQ(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ZhengDiCQDAO zhengDiCQDAO = new ZhengDiCQDAO();
		ZhengDiCQ zhengDiCQ = new ZhengDiCQ();
		
		String ID = request.getParameter("ID");
		String ZhuangTai = request.getParameter("ZhuangTai");
		String JiLuSJ = request.getParameter("JiLuSJ");
		String LuRuR = request.getParameter("LuRuR");
		String XiangMuYDSPBM = request.getParameter("XiangMuYDSPBM");
		String XiangMuYDSPYJ = request.getParameter("XiangMuYDSPYJ");
		String XiangMuYDXKZMH = request.getParameter("XiangMuYDXKZMH");
		String ChaiQianFZDW = request.getParameter("ChaiQianFZDW");
		String ChaiQianFZR = request.getParameter("ChaiQianFZR");
		String XiangMuZDCQGGBM = request.getParameter("XiangMuZDCQGGBM");
		String ChaiQianFW = request.getParameter("ChaiQianFW");
		String ChaiQianSJ = request.getParameter("ChaiQianSJ");
		String ChaiQianFS = request.getParameter("ChaiQianFS");
		String ShangQiYZFJE = request.getParameter("ShangQiYZFJE");
		String BenQiZFJE = request.getParameter("BenQiZFJE");
		String LeiJiZFJE = request.getParameter("LeiJiZFJE");
		String GongChengXMID = request.getParameter("GongChengXMID");
		
		zhengDiCQ.setID(ID);
		zhengDiCQ.setZhuangTai(ZhuangTai);	
		zhengDiCQ.setJiLuSJ(JiLuSJ);	
		zhengDiCQ.setLuRuR(LuRuR);	
		zhengDiCQ.setXiangMuYDSPBM(XiangMuYDSPBM);	
		zhengDiCQ.setXiangMuYDSPYJ(XiangMuYDSPYJ);	
		zhengDiCQ.setXiangMuYDXKZMH(XiangMuYDXKZMH);	
		zhengDiCQ.setChaiQianFZDW(ChaiQianFZDW);	
		zhengDiCQ.setChaiQianFZR(ChaiQianFZR);	
		zhengDiCQ.setXiangMuZDCQGGBM(XiangMuZDCQGGBM);	
		zhengDiCQ.setChaiQianFW(ChaiQianFW);	
		zhengDiCQ.setChaiQianSJ(ChaiQianSJ);	
		zhengDiCQ.setChaiQianFS(ChaiQianFS);	
		zhengDiCQ.setShangQiYZFJE(ShangQiYZFJE);	
		zhengDiCQ.setBenQiZFJE(BenQiZFJE);	
		zhengDiCQ.setLeiJiZFJE(LeiJiZFJE);	
		zhengDiCQ.setGongChengXMID(GongChengXMID);


		zhengDiCQDAO.update(zhengDiCQ);
		
		response.sendRedirect("listZhengDiCQ?GongChengXMID=" + GongChengXMID);
	}
	
	public void deleteZhengDiCQ(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ZhengDiCQDAO zhengDiCQDAO = new ZhengDiCQDAO();
		String ID = request.getParameter("ID");
		String GongChengXMID = request.getParameter("GongChengXMID");
		zhengDiCQDAO.delete(Integer.parseInt(ID));
		response.sendRedirect("listZhengDiCQ?GongChengXMID=" + GongChengXMID);
	}
	
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
